package com.best.onegous.details;

import java.util.ArrayList;

import com.best.onegous.BaseActivity;
import com.best.onegous.R;
import com.best.onegous.Adapter.Bee_PageAdapter;
import com.best.onegous.Rewrite.TouchView;
import com.best.onegous.agreement.Apps;
import com.best.onegous.agreement.Common;
import com.best.onegous.viewpagerindicator.PageIndicator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class PhotoActivity  extends BaseActivity implements OnClickListener{
	private ArrayList<View> photoListView;
	private Bee_PageAdapter photoPageAdapter;
	private ViewPager photoViewPager;
	private PageIndicator mIndicator;
	private Intent intent;
	private LayoutInflater lf;
	private ArrayList<String> imglist = new ArrayList<String>();
	private String sum;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setC(R.layout.activity_photo);
		intent = getIntent();
		imglist = intent.getStringArrayListExtra("img");
		sum = intent.getStringExtra("sum");
		findViewById(R.id.back).setOnClickListener(this);
		
		lf = LayoutInflater.from(this);
		photoViewPager = (ViewPager)findViewById(R.id.fullscreen_viewpager);
		photoListView = new ArrayList<View>();
        photoPageAdapter = new Bee_PageAdapter(photoListView);
		photoViewPager.setAdapter(photoPageAdapter);
		
		 mIndicator = (PageIndicator)findViewById(R.id.indicator);
	        mIndicator.setViewPager(photoViewPager);
		
	        
	        addBannerView();
	        /*mIndicator.notifyDataSetChanged();
            photoPageAdapter.notifyDataSetChanged();*/
	        photoViewPager.setCurrentItem(Integer.parseInt(sum));
	}
	
	 public void addBannerView()
	    {

	       /* if (GoodDetailDraft.getInstance().goodDetail.pictures.size() > 0)
	        {*/
	            photoListView.clear();
	            for (int i = 0; i < imglist.size(); i++)
	            {
	                //PHOTO photo = GoodDetailDraft.getInstance().goodDetail.pictures.get(i);

	            	View view = lf.inflate(R.layout.b3_product_photo_banner_cell, null);
	            	view.findViewById(R.id.all).setOnClickListener(this);
	            	TouchView viewOne = (TouchView) view.findViewById(R.id.oneimg);
	                //ImageView viewOne =  (ImageView) LayoutInflater.from(this).inflate(R.layout.b3_product_photo_banner_cell,null);
	                Apps.imageLoader.displayImage(Common.PHOTOURL+imglist.get(i),viewOne, Apps.allimg);
	               /* shared = getSharedPreferences("userInfo", 0); 
	        		editor = shared.edit();
	        		String imageType = shared.getString("imageType", "mind");

	        		if(imageType.equals("high")) {
	                    imageLoader.displayImage(photo.url,viewOne,EcmobileApp.options);
	        		} else if(imageType.equals("low")) {
	                    imageLoader.displayImage(photo.thumb,viewOne,EcmobileApp.options);
	        		} else {
	        			String netType = shared.getString("netType", "wifi");
	        			if(netType.equals("wifi")) {
	                        imageLoader.displayImage(photo.url,viewOne,EcmobileApp.options);
	        			} else {
	                        imageLoader.displayImage(photo.thumb,viewOne,EcmobileApp.options);
	        			}
	        		}*/

	                photoListView.add(view);


	            }

	            mIndicator.notifyDataSetChanged();
	            photoPageAdapter.notifyDataSetChanged();
	        //}
	    }
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			 finish();
			break;
		case R.id.all:
			 finish();
			break;
		}
	}
}
